/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui2;

import entity.Customer;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import management.CheckForm;
import management.DoEncrypt;
import management.GUIInteraction;
import management.MngCustomer;

/**
 *
 * @author Cucnth
 */
public class GUIMgmCustomer extends javax.swing.JInternalFrame {

    /**
     * Creates new form FrMgmCustomer1
     */
    public GUIMgmCustomer() {
        try {
            initComponents();
            chkStatus.setSelected(true);
            this.setTitle("                                                                                          MANAGEMENT CUSTOMER");
            management.MyConnection.getConnection();
            management.GUIInteraction.readToTable1(management.MngCustomer.sql, tblCustomer);
        } catch (SQLException ex) {
            Logger.getLogger(GUIMgmCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public boolean checkValues() {
        String password = new String(jPasswordField1.getPassword());
        if (!management.CheckForm.isEmpty(txtFullName.getText())) {
            lblErrName.setText("*FullName is not null");
            txtFullName.requestFocus();
            return false;
        }
        if (!management.CheckForm.isName(txtFullName.getText())) {
            lblErrName.setText("*Name isn't only characters");
            return false;
        } else {
            lblErrName.setText("");
        }
        if (!management.CheckForm.isEmpty(txtUserName.getText())) {
            lblErrUser.setText("*Account is not null");
            txtUserName.requestFocus();
            return false;
        } else {
            lblErrUser.setText("");
        }
        if (password.length() < 4) {
            lblErrPass.setText("*Password > 3 characters");
            jPasswordField1.requestFocus();
            return false;
        } else {
            lblErrPass.setText("");
        }
        if (!management.CheckForm.isEmpty(txtDepartment.getText())) {
            lblErrDep.setText("*Department is not null");
            return false;
        } else {
            lblErrDep.setText("");
        }
        if (!management.CheckForm.isAddress(txtDepartment.getText())) {
            lblErrDep.setText("*Department haven't specific character");
            return false;
        } else {
            lblErrDep.setText("");
        }
        if (!management.CheckForm.checkAge(Integer.parseInt(txtAge.getText()))) {
            lblErrAge.setText("*Age must from 18 to 65!");
            return false;
        } else {
            lblErrPhone.setText("");
        }
        if (!management.CheckForm.isEmpty(txtPhone.getText())) {
            lblErrPhone.setText("*Phone is not null");
            return false;
        }
        if (!management.CheckForm.isNumber(txtPhone.getText())) {
            lblErrPhone.setText("*Phone is only interger");
            return false;
        } else {
            lblErrPhone.setText("");
        }
        if (!management.CheckForm.isEmpty(txtAddress.getText())) {
            lblErrAddress.setText("*Address is not null");
            return false;
        } else {
            lblErrAddress.setText("");
        }
        if (!management.CheckForm.isAddress(txtAddress.getText())) {
            lblErrAddress.setText("*Address haven't specific character");
            return false;
        } else {
            lblErrAddress.setText("");
        }
        if (!management.CheckForm.isEmpty(txtEmail.getText())) {
            lblErrEmail.setText("*Email is not null");
            return false;
        }
        if (!management.CheckForm.isEmail(txtEmail.getText())) {
            lblErrEmail.setText("*Email don't valid");
            return false;
        } else {
            lblErrEmail.setText("");
        }
        return true;
    }

    public void Clear() {
        txtAddress.setText("");
        txtAge.setText("");
        txtDepartment.setText("");
        txtEmail.setText("");
        txtFullName.setText("");
        txtPhone.setText("");
        txtSearch.setText("");
        txtUserName.setText("");
        chkGender.setSelected(false);
        chkStatus.setSelected(true);
        jPasswordField1.setText("");
        lblErrEmail.setText("*eg: Email@yahoo.com");
        lblErrAddress.setText("");
        lblErrAge.setText("");
        lblErrDep.setText("");
        lblErrName.setText("");
        lblErrPass.setText("");
        lblErrPhone.setText("");
        lblErrUser.setText("");
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblCustomer = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        lblFullName = new javax.swing.JLabel();
        lblUserName = new javax.swing.JLabel();
        lblPass = new javax.swing.JLabel();
        lblGender = new javax.swing.JLabel();
        lblAge = new javax.swing.JLabel();
        lblPhone = new javax.swing.JLabel();
        lblAddress = new javax.swing.JLabel();
        lblMail = new javax.swing.JLabel();
        lblStatus = new javax.swing.JLabel();
        txtFullName = new javax.swing.JTextField();
        txtUserName = new javax.swing.JTextField();
        txtAge = new javax.swing.JTextField();
        txtPhone = new javax.swing.JTextField();
        txtAddress = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        chkGender = new javax.swing.JCheckBox();
        chkStatus = new javax.swing.JCheckBox();
        jPasswordField1 = new javax.swing.JPasswordField();
        txtDepartment = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        lblErrUser = new javax.swing.JLabel();
        lblErrAge = new javax.swing.JLabel();
        lblErrDep = new javax.swing.JLabel();
        lblErrPhone = new javax.swing.JLabel();
        lblErrAddress = new javax.swing.JLabel();
        lblErrEmail = new javax.swing.JLabel();
        lblErrPass = new javax.swing.JLabel();
        lblErrName = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        btAdd = new javax.swing.JButton();
        btEdit = new javax.swing.JButton();
        btRefresh = new javax.swing.JButton();
        btSearch = new javax.swing.JButton();
        txtSearch = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(1024, 650));

        tblCustomer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Full Name", "User Name", "Department", "Gender", "Age", "Phone", "Address", "Email", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblCustomer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblCustomerMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblCustomer);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblFullName.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblFullName.setText("Full name");
        lblFullName.setPreferredSize(new java.awt.Dimension(51, 15));

        lblUserName.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblUserName.setText("User name");
        lblUserName.setPreferredSize(new java.awt.Dimension(58, 15));

        lblPass.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblPass.setText("Password");
        lblPass.setPreferredSize(new java.awt.Dimension(51, 15));

        lblGender.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblGender.setText("Gender");
        lblGender.setPreferredSize(new java.awt.Dimension(40, 15));

        lblAge.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblAge.setText("Age");
        lblAge.setPreferredSize(new java.awt.Dimension(22, 15));

        lblPhone.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblPhone.setText("Phone");
        lblPhone.setPreferredSize(new java.awt.Dimension(35, 15));

        lblAddress.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblAddress.setText("Address");
        lblAddress.setPreferredSize(new java.awt.Dimension(43, 15));

        lblMail.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblMail.setText("Email");
        lblMail.setPreferredSize(new java.awt.Dimension(27, 15));

        lblStatus.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblStatus.setText("Status");
        lblStatus.setPreferredSize(new java.awt.Dimension(35, 15));

        txtFullName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtFullName.setPreferredSize(new java.awt.Dimension(100, 25));

        txtUserName.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtUserName.setPreferredSize(new java.awt.Dimension(100, 25));
        txtUserName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUserNameActionPerformed(evt);
            }
        });

        txtAge.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtAge.setPreferredSize(new java.awt.Dimension(100, 25));

        txtPhone.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtPhone.setPreferredSize(new java.awt.Dimension(100, 25));

        txtAddress.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtAddress.setPreferredSize(new java.awt.Dimension(100, 25));

        txtEmail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtEmail.setPreferredSize(new java.awt.Dimension(100, 25));

        chkGender.setText("Male");

        chkStatus.setText("Enable");

        jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPasswordField1ActionPerformed(evt);
            }
        });

        txtDepartment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDepartmentActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel1.setText("Department");

        lblErrUser.setFont(new java.awt.Font("Times New Roman", 2, 12)); // NOI18N
        lblErrUser.setForeground(new java.awt.Color(255, 0, 0));

        lblErrAge.setFont(new java.awt.Font("Times New Roman", 2, 12)); // NOI18N
        lblErrAge.setForeground(new java.awt.Color(255, 51, 51));

        lblErrDep.setFont(new java.awt.Font("Times New Roman", 2, 12)); // NOI18N
        lblErrDep.setForeground(new java.awt.Color(255, 0, 0));

        lblErrPhone.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        lblErrPhone.setForeground(new java.awt.Color(255, 0, 0));

        lblErrAddress.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        lblErrAddress.setForeground(new java.awt.Color(255, 0, 0));

        lblErrEmail.setFont(new java.awt.Font("Times New Roman", 2, 12)); // NOI18N
        lblErrEmail.setForeground(new java.awt.Color(255, 0, 51));
        lblErrEmail.setText("*eg: Email@yahoo.com");

        lblErrPass.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        lblErrPass.setForeground(new java.awt.Color(255, 0, 0));

        lblErrName.setFont(new java.awt.Font("Times New Roman", 2, 12)); // NOI18N
        lblErrName.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(lblPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(lblFullName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblUserName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtUserName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                                .addComponent(txtFullName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPasswordField1))
                            .addComponent(chkGender))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lblMail, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblStatus, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblErrName, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblErrUser, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblErrDep, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblErrPass, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblErrAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblErrEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtAge, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                            .addComponent(lblErrAge, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtPhone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtAddress, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(chkStatus, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblErrPhone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblErrAge, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblErrName, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblErrPhone, javax.swing.GroupLayout.DEFAULT_SIZE, 18, Short.MAX_VALUE)
                    .addComponent(lblErrUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(7, 7, 7)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblErrAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblErrPass, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblErrDep, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblErrEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblGender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chkGender)
                    .addComponent(chkStatus))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btAdd.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        btAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/add.png"))); // NOI18N
        btAdd.setText("Add");
        btAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddActionPerformed(evt);
            }
        });

        btEdit.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        btEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/edit.png"))); // NOI18N
        btEdit.setText("Edit");
        btEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditActionPerformed(evt);
            }
        });

        btRefresh.setFont(new java.awt.Font("Times New Roman", 1, 13)); // NOI18N
        btRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/reset_icon.png"))); // NOI18N
        btRefresh.setText("Refresh");
        btRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRefreshActionPerformed(evt);
            }
        });

        btSearch.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        btSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/search.png"))); // NOI18N
        btSearch.setText("Search");
        btSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSearchActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Times New Roman", 2, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("* ID or Name or Department");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23)))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(btSearch))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(btRefresh)))
                .addGap(21, 21, 21))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btAdd)
                    .addComponent(btRefresh, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addComponent(btEdit)
                .addGap(37, 37, 37)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btSearch)
                    .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap(57, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblCustomerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblCustomerMouseClicked
        int i = tblCustomer.getSelectedRow();
        txtFullName.setText(String.valueOf(tblCustomer.getValueAt(i, 1)));
        txtUserName.setText("");
        jPasswordField1.setText("");
        txtDepartment.setText(String.valueOf(tblCustomer.getValueAt(i, 3)));
        String result = (tblCustomer.getValueAt(i, 4).toString());
        if (result.equalsIgnoreCase("Male")) {
            chkGender.setSelected(true);
        } else {
            chkGender.setSelected(false);
        }
        txtAge.setText(String.valueOf(tblCustomer.getValueAt(i, 5)));
        txtPhone.setText(String.valueOf(tblCustomer.getValueAt(i, 6)));
        txtAddress.setText(String.valueOf(tblCustomer.getValueAt(i, 7)));
        txtEmail.setText(String.valueOf(tblCustomer.getValueAt(i, 8)));
        String result2 = tblCustomer.getValueAt(i, 9).toString();
        if (result2.equalsIgnoreCase("Enable")) {
            chkStatus.setSelected(true);
        } else {
            chkStatus.setSelected(false);
        }
    }//GEN-LAST:event_tblCustomerMouseClicked

    private void txtUserNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUserNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUserNameActionPerformed

    private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jPasswordField1ActionPerformed

    private void txtDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDepartmentActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDepartmentActionPerformed

    private void btAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddActionPerformed
        // TODO add your handling code here:


        if (!checkValues()) {
            JOptionPane.showMessageDialog(this, "Insert Unsuccessfull!");
        } else {
            try {
                Customer cus = new Customer();
                MngCustomer managerCus = new MngCustomer();
//            Encrypt Pass
                String passEncrypt = DoEncrypt.encrypt(new String(jPasswordField1.getPassword()));

                cus.setFullName(txtFullName.getText());
                cus.setUserName(txtUserName.getText());
                cus.setPassWord(passEncrypt);
                cus.setDepartmental(txtDepartment.getText());
                if (CheckForm.checkSelected(chkGender)) {
                    cus.setGender("Male");
                } else {
                    cus.setGender("FeMale");
                }
                cus.setAge(Integer.parseInt(txtAge.getText()));
                cus.setPhone(txtPhone.getText());
                cus.setAddress(txtAddress.getText());
                cus.setEmail(txtEmail.getText());
//                cus.setStatus(CheckForm.checkSelected(chkStatus));
                if (CheckForm.checkSelected(chkStatus)) {
                    cus.setStatus("Enable");
                } else {
                    cus.setStatus("Disable");
                }

                if (managerCus.search(txtUserName.getText()) != true) {
                    JOptionPane.showMessageDialog(null, "User name exist in Customer or Manager. Please enter difference user name !");
                } else {
                    managerCus.addCustomer(cus);
                    Clear();
                }
                management.GUIInteraction.readToTable1(management.MngCustomer.sql, tblCustomer);
            } catch (SQLException ex) {
                Logger.getLogger(GUIMgmCustomer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_btAddActionPerformed

    private void btEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditActionPerformed
        try {
            String status = "Disable";
            String gender = "FeMale";

            int selectRow = tblCustomer.getSelectedRow();
            if (selectRow == -1) {
                JOptionPane.showMessageDialog(rootPane, "You don't choise record!");
            } else {
                String name = txtFullName.getText();
                String department = txtDepartment.getText();
                //                boolean gender = Boolean.parseBoolean(chkGender.getText());
                if (chkGender.isSelected()) {
                    gender = "Male";
                }
                int age = Integer.parseInt(txtAge.getText());
                String phone = txtPhone.getText();
                String address = txtAddress.getText();
                String email = txtEmail.getText();
                if (chkStatus.isSelected()) {
                    status = "Enable";
                }
                int id = Integer.parseInt(tblCustomer.getModel().getValueAt(selectRow, 0).toString());
                MngCustomer.updateCustomer(name, department, gender, age, phone, address, email, status, id);
            }
            management.GUIInteraction.readToTable1(management.MngCustomer.sql, tblCustomer);
            Clear();
        } catch (SQLException ex) {
            Logger.getLogger(GUIMgmCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btEditActionPerformed

    private void btRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRefreshActionPerformed
        Clear();
    }//GEN-LAST:event_btRefreshActionPerformed

    private void btSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSearchActionPerformed
        try {
            // TODO add your handling code here:

            String search = txtSearch.getText();
            int a = 0;
            if (CheckForm.isInteger(search)) {
                a = Integer.valueOf(search);
            }
            GUIInteraction.readToTable1("select Customer_Id, Cus_Name, Cus_UserName, Cus_Departmental, Cus_Gender, Cus_Age, Cus_Phone, Cus_Address, Cus_Email, Cus_Status from Customer WHERE Customer_Id = " + a + " OR Cus_Departmental like '%" + search + "%' OR Cus_Name like '%" + search + "%' ", tblCustomer);
        } catch (SQLException ex) {
            Logger.getLogger(GUIMgmCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btSearchActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAdd;
    private javax.swing.JButton btEdit;
    private javax.swing.JButton btRefresh;
    private javax.swing.JButton btSearch;
    private javax.swing.JCheckBox chkGender;
    private javax.swing.JCheckBox chkStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblAge;
    private javax.swing.JLabel lblErrAddress;
    private javax.swing.JLabel lblErrAge;
    private javax.swing.JLabel lblErrDep;
    private javax.swing.JLabel lblErrEmail;
    private javax.swing.JLabel lblErrName;
    private javax.swing.JLabel lblErrPass;
    private javax.swing.JLabel lblErrPhone;
    private javax.swing.JLabel lblErrUser;
    private javax.swing.JLabel lblFullName;
    private javax.swing.JLabel lblGender;
    private javax.swing.JLabel lblMail;
    private javax.swing.JLabel lblPass;
    private javax.swing.JLabel lblPhone;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JTable tblCustomer;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtAge;
    private javax.swing.JTextField txtDepartment;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFullName;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtSearch;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
}
